<?php
require_once("../inc/connect.php");

$old_password = $_POST['oldpass'];
$new_password = $_POST['newPass'];

$result_check = mysql_query("SELECT password FROM member WHERE name = 'test'");
$rowData = mysql_fetch_array($result_check);

if($old_password == $rowData['password']) {
	$result = mysql_query("UPDATE member SET password = '$new_password' WHERE name = 'test'");

	if(mysql_affected_rows() > 0) {
		$response  = "document.getElementById('change_error').style.display = 'none';";
		$response .= "document.getElementById('change_success').style.display = 'block';";
	} else {
		$response  = "document.getElementById('change_success').style.display = 'none';";
		$response .= "document.getElementById('change_error').innerHTML = '<center><b>ผิดพลาด : </b>ไม่สามารถแก้ไขรหัสผ่านได้....โปรดลองอีกครั้ง';";
		$response .= "document.getElementById('change_error').style.display = 'block';";
		$response .= "document.getElementById('admin_oldpass').value = '';";
		$response .= "document.getElementById('admin_newpass').value = '';";
		$response .= "document.getElementById('admin_newpassComfirm').value = '';";
		$response .= "document.getElementById('admin_oldpass').focus();";
	}				

} else {
	$response  = "document.getElementById('change_success').style.display = 'none';";
	$response .= "document.getElementById('change_error').innerHTML = '<center><b>ผิดพลาด : </b>รหัสผ่านเดิมไม่ถูกต้อง';";
	$response .= "document.getElementById('change_error').style.display = 'block';";
	$response .= "document.getElementById('admin_oldpass').value = '';";
	$response .= "document.getElementById('admin_oldpass').focus();";
}

mysql_close($con);

header("content-type:text/javascript; charset=UTF-8");
echo $response;

?>